# -*- coding: utf-8 -*-
# @Time    : 2024/3/10 15:41
# @Author  : xh
# @FileName: fixture.py
# @Software: PyCharm
from jsonpath import jsonpath
import requests
from common.handle_conf import conf


class BaseTest:
    @classmethod
    def admin_log(cls):
        url = conf.get("evn","base_url") + "/login"

        # 准备登录的数据
        params = {
            "user":conf.get("test_data","user"),
            "password":conf.get("test_data","password")
        }
        headers = eval(conf.get("env","headers"))

        # 2、请求登录的接口
        response = requests.post(url = url, json = params,headers = headers)
        res = response.json()
        #提取token，放到请求头中，给后面的用例使用
        admin_token = jsonpath(res,"$..token")[0]
        headers["token"] = "Bearer" + admin_token
        cls.admin_header =headers
